home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Source.bin / AnimatorImage.java < prev    next >
Text File  |  1998-08-21  |  2KB  |  61 lines

  1. package symantec.itools.multimedia;
  2.  
  3. import java.net.URL;
  4. import java.awt.Image;
  5. import java.io.ObjectInputStream;
  6. import java.io.IOException;
  7. import java.awt.MediaTracker;
  8. import java.awt.Component;
  9. import java.util.ResourceBundle;
  10. import java.text.MessageFormat;
  11.  
  12. //    05/30/97    RKM    Moved AnimatorImage class into its own file as the compiler suggested
  13. //  07/15/97    CAR added a default constructor and a constructor which takes a component reference
  14. //                  added a Component reference field and marked fields transient as needed
  15. //                  implemented the Serializable interface
  16. //                  implemented readObject to load the images of the deserialized URLs
  17.  
  18. class AnimatorImage implements java.io.Serializable
  19. {
  20.     URL                    url;
  21.     transient   Image   image;
  22.     transient   boolean    loaded;
  23.     Component           comp = null;
  24.  
  25.     transient protected ResourceBundle errors;
  26.  
  27.     public AnimatorImage() { }
  28.  
  29.     public AnimatorImage(URL u, Image i, boolean l, Component c) {
  30.         this(u, i, l);
  31.         comp = c;
  32.     }
  33.  
  34.     public AnimatorImage(URL u, Image i, boolean l)
  35.     {
  36.         url    = u;
  37.         image  = i;
  38.         loaded = l;
  39.     }
  40.  
  41.     private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
  42.         stream.defaultReadObject();
  43.  
  44.         errors = ResourceBundle.getBundle("symantec.itools.resources.ErrorsBundle");
  45.  
  46.         image = comp.getToolkit().getImage(url);
  47.  
  48.         MediaTracker tracker = new MediaTracker(comp);
  49.         tracker.addImage(image, 0);
  50.         try {
  51.             tracker.waitForAll();
  52.         }
  53.         catch(InterruptedException e) {
  54.             Object[] args = { url };
  55.             throw new IOException(MessageFormat.format(errors.getString("ErrorLoadingImageForURL"), args));
  56.         }
  57.  
  58.         loaded = true;
  59.     }
  60. }
  61.